﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleServiceBus.Bus.Pipeline.PipelineComponents.MessageFiltering
{
    public class MessageFilterComponent : PipelineComponentBase
    {
        public MessageFilterComponent() : base("MessageFilter")
        {
        }

        protected override void ProcessMessage(MessageEnvelope messageEnvelope, IMessageContext context)
        {
            PipelineDirection direction = context.MessagePipeline.PipelineDirection;
            var filter = context.GetLocalService<IMessageFilterService>();
            if (filter != null)
            {
                bool result = filter.Matches(messageEnvelope, direction);
                if (!result)
                    context.AbortMessageProcessing = true;
            }
        }
    }
}
